package com.example.bestudentsystem.demos.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bestudentsystem.demos.web.vo.Classes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ClassMapper extends BaseMapper<Classes> {
    @Select("SELECT t.classid,t.tno AS ltno,COUNT(s.sno) AS student_count,MAX(t.tname) AS lead_teacher " +
            "FROM student s RIGHT JOIN teacher t ON s.classid = t.classid " +
            "WHERE t.classid != 0 AND t.classid LIKE CONCAT('%',#{classId},'%') " +
            "GROUP BY t.classid,t.tno")
    IPage<Classes> selectByPage(IPage<Classes> page,String classId);
    @Update("UPDATE teacher SET classid = #{classId} WHERE tno=#{ltno} ")
    int updateLeadTeacher(Classes classes);
    @Update("update teacher SET classid=0 WHERE classid=#{classId}")
    int updateClassId(Integer classId);
    @Update("update student set classid=0 where classid=#{classId}")
    int updateStudentClassId(Integer classId);
}
